package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.DeviceTypeDTO;
import com.zxy.ziems.server.device.pojo.vo.DeviceTypeVO;
import com.zxy.ziems.server.device.service.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-设备类型
 * @author chdzq
 * @create 2023/3/22
 */
@RestController
@Validated
@RequestMapping("/api")
public class DeviceTypeController {
    /**
     * 新增设备类型
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/add")
    public void add(@Validated(value = DeviceTypeDTO.Add.class) @RequestBody DeviceTypeDTO dto) throws Exception {
        service.add(dto);
    }

    /**
     * 更新设备类型
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/update")
    public void update(@Validated(value = DeviceTypeDTO.Update.class) @RequestBody DeviceTypeDTO dto) throws Exception {
        service.update(dto);
    }

    /**
     * 删除设备类型
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/delete")
    public void delete(@Validated(value = DeviceTypeDTO.Select.class) @RequestBody DeviceTypeDTO dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 查询设备类型列表
     * @return
     */
    @GetMapping("/device/type/list")
    public List<DeviceTypeVO> list() throws Exception {
        return service.viewAll();
    }

    private DeviceTypeService service;

    @Autowired
    public void setService(DeviceTypeService deviceTypeService) {
        this.service = deviceTypeService;
    }
}
